import java.util.Arrays;

public class L59_2 {

    public static void main(String[] args) {
        int[][] ints = new Solution().generateMatrix(4);
        for (int[] anInt : ints) {
            System.out.println(Arrays.toString(anInt));
        }
    }

    static class Solution {
        public int[][] generateMatrix(int n) {
            int begin = 1;
            int i = 0;
            int j = n;
            int[][] result = new int[n][n];

            while (i < j) {
                for (int k = i; k <= j - 2; k++) {
                    result[i][k] = begin++;
                }
                for (int k = i; k <= j - 2; k++) {
                    result[k][j - 1] = begin++;
                }
                for (int k = j - 1; k > i; k--) {
                    result[j - 1][k] = begin++;
                }
                for (int k = j - 1; k > i; k--) {
                    result[k][i] = begin++;
                }
                i++;
                j--;
            }
            if (n % 2 != 0) {
                result[n / 2][n / 2] = begin;
            }
            return result;
        }
    }
}
